//
//  L_Singleton.m
//  音悦咖
//
//  Created by dllo on 15/7/17.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "L_Singleton.h"
#import "STKAudioPlayer.h"
#import <AVFoundation/AVFoundation.h>
#import "L_footPlaytabBar.h"
static L_Singleton *single = nil;

@implementation L_Singleton

- (void)dealloc
{
    [_state release];
    [_streamer release];
    [_url release];
    [_array release];
    [_songName release];
    [_singerName release];
    [_pic release];
    [_song_id release];
    [_playUrl release];
    [_footplayView release];
    [_time release];
    [super dealloc];
}


+ (L_Singleton *)shareManager
{
    
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        
        if (!single) {
            
            single = [[L_Singleton alloc] init];
        
        }
    });
    
    return single;
    
}



#pragma mark - 更新播放器设置
- (void)updatePlayerSetting
{

    // 更新播放按钮状态
    [self.footplayView.playOrPause setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
    self.state = nil;
    
    // 更新曲目.标题等
    self.playUrl = [[[self.array[self.index] url_list] lastObject] objectForKey:@"url"];
    self.playUrl = self.playUrl;
    self.footplayView.songName.text = [self.array[self.index] song_name];
    self.footplayView.songerName.text = [self.array[self.index] singer_name];
    [self.footplayView.mainImage setImageWithURL:[NSURL URLWithString:[[[self.array[self.index] mv_list] firstObject] objectForKey:@"pic_url"]] placeholderImage:[UIImage imageNamed:@"headimg@2x.png"]];
    
    
    //播放
    [self playWithUrl:self.playUrl];
    self.state = @"playing";
    
    
}



#pragma mark - 播放网络音频方法
- (void)playWithUrl:(NSString *)url
{
    [self stop];
    self.streamer = [[STKAudioPlayer alloc] init];
    [self.streamer play:url];
    
}

#pragma mark - 停止播放方法
- (void)stop
{
    if (self.streamer) {
        
        [self.streamer stop];
    }
}



@end
